MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;====================== Dining Door Controller ====================== 00002 ; Roger Himka 00003 ; R1: Revised 2/8/2012 No door locked error 00004 ; R2: Revised 10/19/2012 Door not closing - not an error - keep trying 00005 ; 00006 ; 00007 ;==================================================================== 00008 00009 #include 00001 LIST 00002 ; P16F684.INC Standard Header File, Version 1.03 Microchip Technology, Inc. 00379 LIST 2007 33D4 00010 __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_O FF) 00011 00012 ; --- INPUTS --- 00013 #define DOOR_IS_OPEN_LIMIT_SWITCH 0 ; A0 "Door is Open" limit switch - normally open 00014 #define DOOR_EDGE_CONTACT_SWITCH 1 ; A1 "Door Edge Contact" switch - Normally closed 00015 #define OBSTRUCTION_DETECTED_BEAM 2 ; A2 Infra-red beam "Obstruction Detected" - pulses w hen clear 00016 #define DOOR_IS_UNLOCKED_SWITCH 3 ; A3 "Door is Unlocked" switch (also Vpp when program ming) - normally open 00017 #define DOOR_IS_CLOSED_LIMIT_SWITCH 4 ; A4 "Door is Closed" limit switch - normally open 00018 #define HOLD_DOOR_OPEN_SWITCH 5 ; A5 "Hold Door Open" switch - normally closed 00019 00020 #define DOOR_OPEN_TIME_POT 3 ; C3 Door "Open Time" potentiometer 00021 #define OPEN_THE_DOOR_SWITCH 4 ; C4 "Open the Door" switch - normally open 00022 00023 ; --- Outputs --- 00024 #define OPEN_DOOR_AIR_VALVE 0 ; C0 Turn on "Open Door" air valve 00025 #define CLOSE_DOOR_AIR_VALVE 1 ; C1 Turn on "Close Door" air valve 00026 #define ERROR_SONALERT 2 ; C2 Sonalert for error identification 00027 #define AUX_OUTPUT 5 ; C5 Auxillary output 00028 00029 ; --- Operational Constants --- 00030 #define AIR_PULSE_TRIES 5 ; Number of pulses before the air is fully turne d on 00031 #define TIME_TO_OPEN_DOOR 30h ; Expected max opening time in tenth-seconds 00032 #define TIME_TO_CLOSE_DOOR 30h ; Expected max closing time in tenth-seconds 00033 #define MIN_DOOR_STAY_OPEN_TIME 10h ; Min time door remains open after pushing "Open the doo r" button in tenth-seconds 00034 00035 ; --- System States --- 00036 #define POWERING_UP 0 00037 #define DOOR_IS_LOCKED 1 00038 #define DOOR_IS_CLOSED 2 00039 #define DOOR_IS_OPENING 3 00040 #define DOOR_IS_OPEN 4 00041 #define DOOR_IS_CLOSING 5 00042 00043 ; --- Error Return Codes, Number of beeps --- 00044 #define NOT_OPENING 1 00045 #define NOT_CLOSING 2 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00046 00047 00048 cblock 0x20 00000020 00049 AirPulseCount 00000021 00050 BeepSequence 00000022 00051 BeepCount 00000023 00052 DoorOpenDuration 00000024 00053 ObstructionDetected 00000025 00054 PortCValue 00000026 00055 ReturnedCode 00000027 00056 SystemState 00000028 00057 Timer2Comp 00000029 00058 TenthSeconds 00059 endc 00060 00061 ;===================================================== 0000 00062 org 0 0000 00063 Start: 0000 0000 00064 nop 0001 0000 00065 nop 00066 00067 ;-------- INITIALIZATIONS -------- 00068 00069 ;-------- Page 1 Initialization -------- 00070 0002 1683 00071 bsf STATUS,RP0 ; Select Register Bank 1 00072 0003 3018 00073 movlw b'00011000' ; Make PortC 0,1,2,5 outputs, 3,4 inputs Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 0004 0087 00074 movwf TRISC 00075 0005 3038 00076 movlw b'00111000' ; Configure Timer0. Sourced from external (IR beam detector) Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 0006 0081 00077 movwf OPTION_REG 00078 0007 3080 00079 movlw b'10000000' Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 0008 0091 00080 movwf ANSEL ; Make PortA all digital, C3(AN7) analog for ADC 0009 303F 00081 movlw b'00111111' Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 000A 0085 00082 movwf TRISA ; Make PortA all input Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 000B 1381 00083 bcf OPTION_REG,NOT_RAPU ; Enable pull-up enabling 000C 303F 00084 movlw b'00111111' Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 000D 0095 00085 movwf WPUA ; Enable pull-ups to selected bits 00086 00087 ; Set up Timer 2 000E 30CE 00088 movlw 0CE ; Value in comparison register - 208d Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 000F 0092 00089 movwf PR2 00090 00091 ; Set up Analog to Digital conversion clock rate MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0010 3050 00092 movlw b'01010000' ; ADC use Fosc / 16 conversion rate Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 0011 081F 00093 movfw ADCON1 00094 0012 1283 00095 bcf STATUS,RP0 ; Un-Select Register Page 1 (Select Page 0) 00096 00097 ;-------- Page 0 Initialization -------- 00098 00099 ; Set up Timer0 to count pulses from the IR beam b'X0111XXX' 00100 ; For Bank1, bit 6 INTEDG =0 (falling edge), bit 5 T0CS =1 (external input), 00101 ; bit 4 T0SE =1 (inc on high-to=low), bit 3 PSA =1 00102 ; (prescaler assigned to WDT), bits 2=0 PS<2:0> =XXX 00103 ; Set up Timer2 for 0.01 second interval 0013 3017 00104 movlw b'00010111' ; Postscaler=3 0010, Timer2=On 1, Prescaler=16 11 00105 ; movlw b'01001111' ; For timer 2 test 0014 0092 00106 movwf T2CON 00107 0015 3007 00108 movlw 0x07 ; Digital I/O 0016 0099 00109 movwf CMCON0 00110 0017 301D 00111 movlw b'00011101' ; Potentiometer on AN7 (C3, pin 7), 0018 009F 00112 movwf ADCON0 ; left justified, and turn on the A2D module 00113 00114 ;-------- Hardware Initialization -------- 0019 0187 00115 clrf PORTC ; All outputs off 00116 00117 ;-------- Variable Initialization -------- 00118 ; clrf PortCValue 00119 00120 ;=========================================================== 00121 00122 ;=========================================================== 00123 ;-------- Main Programs -------- 00124 001A 00125 PoweringUp: ; --- Powering-up Sequence ---------- 001A 3000 00126 movlw POWERING_UP 001B 00A7 00127 movwf SystemState 001C 1985 00128 btfsc PORTA,DOOR_IS_UNLOCKED_SWITCH 001D 282B 00129 goto DoorIsLocked ; Do not turn on the air. 00130 ; Door is already unlocked. Slowly make sure that the door is closed 001E 3005 00131 movlw AIR_PULSE_TRIES 001F 00A0 00132 movwf AirPulseCount ; Number of pulses that will be tried 0020 00133 PULoop: 0020 1487 00134 bsf PORTC,CLOSE_DOOR_AIR_VALVE ; Pulse the air for 0.2 seconds 0021 20BE 00135 call WaitTenthSecond 0022 20BE 00136 call WaitTenthSecond 0023 1C05 00137 btfss PORTA,DOOR_IS_OPEN_LIMIT_SWITCH ; Check limit switch 0024 283D 00138 goto DoorIsClosed ; Limit switch activated,. Door is clos ed. 0025 1087 00139 bcf PORTC,CLOSE_DOOR_AIR_VALVE ; Release pressure to prevent rapid door movemen t 0026 208B 00140 call WaitOneSecond 0027 0BA0 00141 decfsz AirPulseCount,f ; Have sufficient pulses been applied MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0028 2820 00142 goto PULoop ; No. Apply another pulse 0029 1487 00143 bsf PORTC,CLOSE_DOOR_AIR_VALVE ;Yes. Turn on the system (CLOSE_THE_DOOR) air. 00144 ; goto CloseTheDoor ; Use the normal OpenTheDoor sequence 002A 283D 00145 goto DoorIsClosed ; 00146 ; --- End of Powering-up Sequence --- 00147 00148 002B 00149 DoorIsLocked: ; --- Door is Locked Sequence --------- 002B 3001 00150 movlw DOOR_IS_LOCKED 002C 00A7 00151 movwf SystemState 002D 1007 00152 bcf PORTC,OPEN_DOOR_AIR_VALVE ; Release air from both valves 002E 1087 00153 bcf PORTC,CLOSE_DOOR_AIR_VALVE 002F 1D85 00154 btfss PORTA,DOOR_IS_UNLOCKED_SWITCH ; Monitor the Door is Locked switch 0030 283B 00155 goto DoorHasBeenUnlocked Warning[207]: Found label after column 1. (DILCheckOpenSwitch) 0031 00156 DILCheckOpenSwitch: 0031 1E07 00157 btfss PORTC,OPEN_THE_DOOR_SWITCH ; If Open the Door switch is activated 0032 2835 00158 goto DILCheckHoldSwitch 0033 1507 00159 bsf PORTC,ERROR_SONALERT ; Begin sounding the sonalert 0034 282B 00160 goto DoorIsLocked Warning[207]: Found label after column 1. (DILCheckHoldSwitch) 0035 00161 DILCheckHoldSwitch: 0035 1E85 00162 btfss PORTA,HOLD_DOOR_OPEN_SWITCH ; If Hold Door Open switch is activated 0036 2839 00163 goto DILNoError 0037 1507 00164 bsf PORTC,ERROR_SONALERT ; Begin sounding the Sonalert 0038 282B 00165 goto DoorIsLocked Warning[207]: Found label after column 1. (DILNoError) 0039 00166 DILNoError: ; If neither switch is act ivated 0039 1107 00167 bcf PORTC,ERROR_SONALERT ; Turn off the Sonalert 003A 282B 00168 goto DoorIsLocked 003B 00169 DoorHasBeenUnlocked: ; When door has been unlocked 003B 1107 00170 bcf PORTC,ERROR_SONALERT ; Turn off the Sonalert 00171 ; bsf PORTC,CLOSE_DOOR_AIR_VALVE ; Activate the Close Door air valv e - hold door closed 003C 281A 00172 goto PoweringUp ; Use the Powering Up Sequ ence 00173 ; --- End of Door is Locked Sequence --------- 00174 00175 003D 00176 DoorIsClosed: ; ---------- Door is Closed Sequence ---------- 00177 ; Wait for "Open the Door" or "Hold Door Open" activation. 003D 3002 00178 movlw DOOR_IS_CLOSED 003E 00A7 00179 movwf SystemState 003F 00180 WaitForOpenTheDoor: 003F 1E07 00181 btfss PORTC,OPEN_THE_DOOR_SWITCH ; If Open the Door switch is activated 0040 2846 00182 goto OpenTheDoor ; Go to Open the Door sequence 0041 1A85 00183 btfsc PORTA,HOLD_DOOR_OPEN_SWITCH ; If Hold Door Open switch is activated 0042 2846 00184 goto OpenTheDoor ; Go to Open the Door sequence 0043 1985 00185 btfsc PORTA,DOOR_IS_UNLOCKED_SWITCH ; If the door has been locked 0044 282B 00186 goto DoorIsLocked ; Go to Door is Locked sequence 0045 283D 00187 goto DoorIsClosed ; Else the door will remain closed 00188 ; ---------- End of Door is Closed Sequence ---------- MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00189 00190 0046 00191 OpenTheDoor: ; ---------- Door is Opening Sequence ---------- 0046 3003 00192 movlw DOOR_IS_OPENING 0047 00A7 00193 movwf SystemState 0048 206B 00194 call GetStayOpenDuration ; Read the "Open Time" potentiometer to set the St ay Open Duration 00195 00196 ; Make sure that door is not locked 0049 1985 00197 btfsc PORTA,DOOR_IS_UNLOCKED_SWITCH ; IF "Door is Locked" 004A 282B 00198 goto DoorIsLocked ; Go to Door is Locked seq uence 00199 004B 1407 00200 bsf PORTC,OPEN_DOOR_AIR_VALVE ; Energize the "open door" valve 00201 00202 ; call WaitHalfSecond 00203 ; btfss PORTA,DOOR_IS_CLOSED_LIMIT_SWITCH ; Verify that the door has begun opening 00204 ; goto DoorIsLocked ; Else assume that the doo r is locked 00205 004C 00206 OTDWait: 004C 1805 00207 btfsc PORTA,DOOR_IS_OPEN_LIMIT_SWITCH ; Wait until door is completely open 004D 284C 00208 goto OTDWait 00209 004E 284F 00210 EndWFOTD: goto DoorIsOpen ; ENDIF 00211 ; ---------- End of Door is Opening Sequence ---------- 00212 00213 004F 00214 DoorIsOpen: ; ---------- Door is Open Sequence ---------- 004F 3004 00215 movlw DOOR_IS_OPEN 0050 00A7 00216 movwf SystemState 0051 1A85 00217 btfsc PORTA,HOLD_DOOR_OPEN_SWITCH ; IF "Hold Door Open" is activated 0052 285A 00218 goto HoldingOpen ; Proceed to Holding Open 00219 ; ELSE 0053 00220 OpenTimeWait: ; ENDIF 0053 0823 00221 movf DoorOpenDuration,W ; Number of tenths of seconds to k eep the door open 0054 2082 00222 call EventMaxTime ; Wait for the "Open Time" delay 0055 1903 00223 btfsc STATUS,Z ; IF an obstruction has been detec ted, re-check the Hold Open 0056 285D 00224 goto CloseTheDoor ; switch, restart the Hold Open timer if not the Hold switch 0057 1A85 00225 btfsc PORTA,HOLD_DOOR_OPEN_SWITCH ; Re-check the "Hold Door Open" switch 0058 285A 00226 goto HoldingOpen ; 0059 284F 00227 goto DoorIsOpen ; Re-start the open-time timer 00228 005A 00229 HoldingOpen: 005A 1A85 00230 btfsc PORTA,HOLD_DOOR_OPEN_SWITCH ; WHILE "Hold Door Open" is activated 005B 285A 00231 goto HoldingOpen ; Wait until "Hold Door Op en" is deactivated 005C 285D 00232 goto CloseTheDoor ; THEN Close the door 00233 ; ---------- End of Door is Open Sequence ---------- 00234 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00235 005D 00236 CloseTheDoor: ; ---------- Door is Closing Sequence ---------- 005D 3005 00237 movlw DOOR_IS_CLOSING 005E 00A7 00238 movwf SystemState 005F 1007 00239 bcf PORTC,OPEN_DOOR_AIR_VALVE ; Deactivate the "Open Door" valve 0060 3030 00240 movlw TIME_TO_CLOSE_DOOR ; Wait expected door closing time 0061 2082 00241 call EventMaxTime 0062 00A6 00242 movwf ReturnedCode 0063 1D03 00243 btfss STATUS,Z 0064 2866 00244 goto CTDObstruction 00245 ; There was a time-out for the door closing (took too long) 00246 ;R2: call ErrorAlertNotClosing 00247 ;R2 goto DoorIsClosed 0065 285D 00248 goto CloseTheDoor ;R2 0066 00249 CTDObstruction: 0066 3004 00250 movlw DOOR_IS_CLOSED_LIMIT_SWITCH ; If the Door Closed limit switch was the "obstruc tion" 0067 0626 00251 xorwf ReturnedCode,W 0068 1903 00252 btfsc STATUS,Z 0069 283D 00253 goto DoorIsClosed ; Proceed to Door is Closed sequen ce 00254 ; If during that interval "Open Door" or "Door Edge Contact" or "Beam Obstruction Detected " 00255 ; or "Hold Open" were activated, activate the "Open the Door" sequence. 006A 2846 00256 goto OpenTheDoor 006B 00257 EndCloseTheDoor: 00258 ; ---------- End of Door is Closing Sequence ---------- 00259 00260 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00261 00262 ;===================================================================================== 00263 ; ----------- Read the potentiometer to get the number of ---------- 00264 ; tenths of a second (0 to 31) to add to the basic 00265 ; hold open time. 006B 00266 GetStayOpenDuration: 00267 ;GOTLoop: 00268 ; nop ; wait 5uS for A2D amp to settle and capacitor t o charge. 00269 ; nop ; wait 1uS 00270 ; nop ; wait 1uS 00271 ; nop ; wait 1uS 00272 ; nop ; wait 1uS 006B 149F 00273 bsf ADCON0,GO ; start conversion 006C 1C9F 00274 btfss ADCON0,GO ; this bit will change to zero when the conversion is complete 006D 286C 00275 goto $-1 00276 006E 0000 00277 nop 006F 0000 00278 nop 0070 0000 00279 nop 0071 0000 00280 nop 0072 0000 00281 nop 0073 149F 00282 bsf ADCON0,GO 0074 1C9F 00283 btfss ADCON0,GO MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0075 2874 00284 goto $-1 00285 0076 0000 00286 nop 00287 0077 081E 00288 movf ADRESH,W ; Get the high 8 bits if the A/D value 0078 39F8 00289 andlw b'11111000' ; Clear the low-order bits 0079 00A3 00290 movwf DoorOpenDuration ; Temporarily store the value 007A 1003 00291 bcf STATUS,C ; Clear the CARRY bit 007B 0CA3 00292 rrf DoorOpenDuration,F ; Rotate right three times (max time incre ment 31 tenths of a second) 007C 0CA3 00293 rrf DoorOpenDuration,F 007D 0CA3 00294 rrf DoorOpenDuration,F 007E 0823 00295 movf DoorOpenDuration,W ; Store the added stay-open duration 00296 ;movwf PORTC 00297 ;goto GetOpenDuration 007F 3E10 00298 addlw MIN_DOOR_STAY_OPEN_TIME ; Tenths of a second 0080 00A3 00299 movwf DoorOpenDuration 00300 0081 0008 00301 return 00302 ;===================================================================================== 00303 00304 ;================================================================================= 00305 ; ---------- Event timeout timers ---------- 00306 ; -------- Wait # tenth-seconds in W register 00307 00308 ; Returns after the expected maximum time provided in the W register unless 00309 ; an "obstruction" has been encountered, in which case the timer then terminates early. 00310 0082 00311 EventMaxTime: 0082 00A9 00312 movwf TenthSeconds 0083 00313 EventMaxTimeLoop: 0083 2095 00314 call WaitTenthWithOD 0084 00A6 00315 movwf ReturnedCode 00316 ;movf ObstructionDetected,w 0085 1D03 00317 btfss STATUS,Z ; See if there was an Obstruction code returned 00318 ;nop 0086 2889 00319 goto EndEMTL ; There was a code. Terminate timing. 0087 0BA9 00320 decfsz TenthSeconds,F ; No code. 0088 2883 00321 goto EventMaxTimeLoop; Continue with the timing 0089 00322 EndEMTL: 0089 0826 00323 movf ReturnedCode,w 008A 0008 00324 return 00325 00326 ; --- Delay times without obstruction monitoring --- 008B 00327 WaitOneSecond: 008B 300A 00328 movlw 0Ah ; 10d 10th seconds 008C 00A9 00329 movwf TenthSeconds 008D 2891 00330 goto TimerLoop 00331 008E 00332 WaitHalfSecond: 008E 3005 00333 movlw 05h ; 5d 10th seconds 008F 00A9 00334 movwf TenthSeconds 0090 2891 00335 goto TimerLoop MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 8 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00336 0091 00337 TimerLoop: 0091 20BE 00338 call WaitTenthSecond 0092 0BA9 00339 decfsz TenthSeconds,f 0093 2891 00340 goto TimerLoop 00341 0094 0008 00342 return 00343 ;=================================================================================== 00344 00345 ;=================================================================================== 00346 ; Tenth of a second delay with Obstruction monitoring 00347 ; -------- Timer 2 providing 0.01 seconds --------- 00348 ; 00349 ; Timer 0 is counting pulses from the IR detector at approximately 150 Hz 00350 ; when the beam is unobstructed. 00351 ; 00352 ; With OD, this timing loop will terminate early if there is an "obstruction" 00353 ; detected (IR beam, Door Edge, Open Door, Hold Open, Door at Limit) 00354 ; 00355 0095 00356 WaitTenthWithOD: 0095 300A 00357 movlw 0Ah ; 10 counts for tenth second 0096 00A8 00358 movwf Timer2Comp 0097 0181 00359 clrf TMR0 ; Clear the IR pulse count 0098 0A81 00360 incf TMR0,f 0099 01A4 00361 clrf ObstructionDetected ; Clear the Obstruction Detected indicator 00362 00363 009A 00364 Timer2Loop1: 009A 1C8C 00365 btfss PIR1,TMR2IF 009B 289A 00366 goto Timer2Loop1 00367 ; TIMER2 has rolled over 009C 108C 00368 bcf PIR1,TMR2IF ; Clear the flag 00369 009D 00370 PulseCheck: ; Get the number of IR pulses from TIMER0 009D 0801 00371 movf TMR0,w 009E 1D03 00372 btfss STATUS,Z 009F 28A4 00373 goto GotPulses 00A0 00374 NoPulses: ; There is an IR beam obstruction 00A0 3002 00375 movlw OBSTRUCTION_DETECTED_BEAM 00A1 00A4 00376 movwf ObstructionDetected 00A2 1687 00377 bsf PORTC,AUX_OUTPUT 00A3 28BC 00378 goto TLWODEnd 00A4 00379 GotPulses: ; The IR beam is not obstructed 00A4 1287 00380 bcf PORTC,AUX_OUTPUT 00A5 0181 00381 clrf TMR0 ; Clear the pulse count for the next cycle 00A6 00382 EndPulseCheck: 00383 00A6 00384 CheckDoorEdge: 00A6 1C85 00385 btfss PORTA,DOOR_EDGE_CONTACT_SWITCH 00A7 28AB 00386 goto CheckOpenDoor 00387 ; The Door Edge Contact Switch has been activated. 00A8 3001 00388 movlw DOOR_EDGE_CONTACT_SWITCH MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 9 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00A9 00A4 00389 movwf ObstructionDetected 00AA 28BC 00390 goto TLWODEnd 00391 00AB 00392 CheckOpenDoor: 00AB 1A07 00393 btfsc PORTC,OPEN_THE_DOOR_SWITCH 00AC 28B0 00394 goto CheckHoldOpen 00395 ; The Open the Door switch has been activated 00AD 3004 00396 movlw OPEN_THE_DOOR_SWITCH 00AE 00A4 00397 movwf ObstructionDetected 00AF 28BC 00398 goto TLWODEnd 00399 00B0 00400 CheckHoldOpen: 00B0 1E85 00401 btfss PORTA,HOLD_DOOR_OPEN_SWITCH 00B1 28B5 00402 goto CheckClosedLimitSwitch 00403 ; The Hold Door Open switch has been activated 00B2 3005 00404 movlw HOLD_DOOR_OPEN_SWITCH 00B3 00A4 00405 movwf ObstructionDetected 00B4 28BC 00406 goto TLWODEnd 00407 00B5 00408 CheckClosedLimitSwitch: 00B5 1A05 00409 btfsc PORTA,DOOR_IS_CLOSED_LIMIT_SWITCH 00B6 28BA 00410 goto NoObstructionsDetected 00411 ; Door has reach its "closed" limit 00B7 3004 00412 movlw DOOR_IS_CLOSED_LIMIT_SWITCH 00B8 00A4 00413 movwf ObstructionDetected 00B9 28BC 00414 goto TLWODEnd 00415 00BA 00416 NoObstructionsDetected: 00BA 0BA8 00417 decfsz Timer2Comp,f 00BB 289A 00418 goto Timer2Loop1 00419 00BC 00420 TLWODEnd: 00BC 0824 00421 movf ObstructionDetected,w 00BD 0008 00422 return 00423 00424 00425 ; ------- Tenth of a second wait - No obstruction monitoring ------- 00BE 00426 WaitTenthSecond: 00BE 300A 00427 movlw 0Ah ; 10 counts for tenth second 00BF 00A8 00428 movwf Timer2Comp 00429 00C0 00430 Timer2Loop2: 00C0 1C8C 00431 btfss PIR1,TMR2IF 00C1 28C0 00432 goto Timer2Loop2 00433 ; TIMER2 has rolled over 00C2 108C 00434 bcf PIR1,TMR2IF ; Clear the flag 00C3 0BA8 00435 decfsz Timer2Comp,f 00C4 28C0 00436 goto Timer2Loop2 00437 00C5 00438 WTSEnd: 00C5 0824 00439 movf ObstructionDetected,w 00C6 0008 00440 return 00441 ;==================================================================== MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 10 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00442 ;++++++++++++++++++++++++++++++ ERROR HANDLING +++++++++++++++++++++++++++++++++++++ 00443 ;Error Alerts 00444 00C7 00445 ErrorAlertNotOpening: ; Not Opening: Door not opening fully 00C7 3001 00446 movlw NOT_OPENING 00C8 00A1 00447 movwf BeepSequence 00C9 28CD 00448 goto ErrorBeeping 00449 00CA 00450 ErrorAlertNotClosing: ; Not Closing: Door not closing fully 00CA 3002 00451 movlw NOT_CLOSING 00CB 00A1 00452 movwf BeepSequence 00CC 28CD 00453 goto ErrorBeeping 00454 00CD 00455 ErrorBeeping: 00456 ; bcf PORTC,OPEN_DOOR_AIR_VALVE ; Deactivate both valves 00457 ; bcf PORTC,CLOSE_DOOR_AIR_VALVE 00CD 00458 BeepsLoop: 00CD 0821 00459 movf BeepSequence,W 00CE 00A2 00460 movwf BeepCount 00CF 1507 00461 Beeps: bsf PORTC,ERROR_SONALERT 00D0 20BE 00462 call WaitTenthSecond 00D1 1107 00463 bcf PORTC,ERROR_SONALERT 00D2 20BE 00464 call WaitTenthSecond 00465 ; decf BeepSequence,f 00D3 0BA2 00466 decfsz BeepCount,F 00467 ; btfsc STATUS,Z 00D4 28CF 00468 goto Beeps 00D5 208B 00469 call WaitOneSecond 00470 ; Check to see if door has manually moved to desired position 00D6 3001 00471 movlw NOT_OPENING 00D7 0621 00472 xorwf BeepSequence,W 00D8 1D03 00473 btfss STATUS,Z 00D9 28DD 00474 goto BeepsCheckClosed 00475 ; Check for Open door 00DA 1805 00476 btfsc PORTA,DOOR_IS_OPEN_LIMIT_SWITCH 00DB 28CD 00477 goto BeepsLoop 00DC 0008 00478 return ; Door has closed Warning[207]: Found label after column 1. (BeepsCheckClosed) 00DD 00479 BeepsCheckClosed: 00480 ; Check for Closed door 00DD 1A05 00481 btfsc PORTA,DOOR_IS_CLOSED_LIMIT_SWITCH 00DE 28CD 00482 goto BeepsLoop ; Power cycle to exit loop 00DF 0008 00483 return ; Door has opened 00484 ;===================================================================================== 00485 00486 end MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 11 SYMBOL TABLE LABEL VALUE ADCON0 0000001F ADCON1 0000009F ADCS0 00000004 ADCS1 00000005 ADCS2 00000006 ADFM 00000007 ADIE 00000006 ADIF 00000006 ADON 00000000 ADRESH 0000001E ADRESL 0000009E AIR_PULSE_TRIES 5 ANS0 00000000 ANS1 00000001 ANS2 00000002 ANS3 00000003 ANS4 00000004 ANS5 00000005 ANS6 00000006 ANS7 00000007 ANSEL 00000091 AUX_OUTPUT 5 AirPulseCount 00000020 BeepCount 00000022 BeepSequence 00000021 Beeps 000000CF BeepsCheckClosed 000000DD BeepsLoop 000000CD C 00000000 C1IE 00000003 C1IF 00000003 C1INV 00000004 C1OUT 00000006 C2IE 00000004 C2IF 00000004 C2INV 00000005 C2OUT 00000007 C2SYNC 00000000 CCP1CON 00000015 CCP1IE 00000005 CCP1IF 00000005 CCP1M0 00000000 CCP1M1 00000001 CCP1M2 00000002 CCP1M3 00000003 CCPR1H 00000014 CCPR1L 00000013 CHS0 00000002 CHS1 00000003 CHS2 00000004 CIS 00000003 CLOSE_DOOR_AIR_VALVE 1 CM0 00000000 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 12 SYMBOL TABLE LABEL VALUE CM1 00000001 CM2 00000002 CMCON0 00000019 CMCON1 0000001A CTDObstruction 00000066 CheckClosedLimitSwitch 000000B5 CheckDoorEdge 000000A6 CheckHoldOpen 000000B0 CheckOpenDoor 000000AB CloseTheDoor 0000005D DC 00000001 DC1B0 00000004 DC1B1 00000005 DILCheckHoldSwitch 00000035 DILCheckOpenSwitch 00000031 DILNoError 00000039 DOOR_EDGE_CONTACT_SWITCH 1 DOOR_IS_CLOSED 2 DOOR_IS_CLOSED_LIMIT_SWITCH 4 DOOR_IS_CLOSING 5 DOOR_IS_LOCKED 1 DOOR_IS_OPEN 4 DOOR_IS_OPENING 3 DOOR_IS_OPEN_LIMIT_SWITCH 0 DOOR_IS_UNLOCKED_SWITCH 3 DOOR_OPEN_TIME_POT 3 DoorHasBeenUnlocked 0000003B DoorIsClosed 0000003D DoorIsLocked 0000002B DoorIsOpen 0000004F DoorOpenDuration 00000023 ECCPAS 00000017 ECCPAS0 00000004 ECCPAS1 00000005 ECCPAS2 00000006 ECCPASE 00000007 EEADR 0000009B EECON1 0000009C EECON2 0000009D EEDAT 0000009A EEDATA 0000009A EEIE 00000007 EEIF 00000007 ERROR_SONALERT 2 EndCloseTheDoor 0000006B EndEMTL 00000089 EndPulseCheck 000000A6 EndWFOTD 0000004E ErrorAlertNotClosing 000000CA ErrorAlertNotOpening 000000C7 ErrorBeeping 000000CD EventMaxTime 00000082 EventMaxTimeLoop 00000083 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 13 SYMBOL TABLE LABEL VALUE F 00000001 FSR 00000004 GIE 00000007 GO 00000001 GO_DONE 00000001 GetStayOpenDuration 0000006B GotPulses 000000A4 HOLD_DOOR_OPEN_SWITCH 5 HTS 00000002 HoldingOpen 0000005A INDF 00000000 INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 IOC 00000096 IOC0 00000000 IOC1 00000001 IOC2 00000002 IOC3 00000003 IOC4 00000004 IOC5 00000005 IOCA 00000096 IOCA0 00000000 IOCA1 00000001 IOCA2 00000002 IOCA3 00000003 IOCA4 00000004 IOCA5 00000005 IRCF0 00000004 IRCF1 00000005 IRCF2 00000006 IRP 00000007 LTS 00000001 MIN_DOOR_STAY_OPEN_TIME 10h NOT_BOD 00000000 NOT_CLOSING 2 NOT_DONE 00000001 NOT_OPENING 1 NOT_PD 00000003 NOT_POR 00000001 NOT_RAPU 00000007 NOT_T1SYNC 00000002 NOT_TO 00000004 NoObstructionsDetected 000000BA NoPulses 000000A0 OBSTRUCTION_DETECTED_BEAM 2 OPEN_DOOR_AIR_VALVE 0 OPEN_THE_DOOR_SWITCH 4 OPTION_REG 00000081 OSCCON 0000008F OSCTUNE 00000090 OSFIE 00000002 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 14 SYMBOL TABLE LABEL VALUE OSFIF 00000002 OSTS 00000003 OTDWait 0000004C ObstructionDetected 00000024 OpenTheDoor 00000046 OpenTimeWait 00000053 P1M0 00000006 P1M1 00000007 PCL 00000002 PCLATH 0000000A PCON 0000008E PDC0 00000000 PDC1 00000001 PDC2 00000002 PDC3 00000003 PDC4 00000004 PDC5 00000005 PDC6 00000006 PEIE 00000006 PIE1 0000008C PIR1 0000000C PORTA 00000005 PORTC 00000007 POWERING_UP 0 PR2 00000092 PRSEN 00000007 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 PSSAC0 00000002 PSSAC1 00000003 PSSBD0 00000000 PSSBD1 00000001 PULoop 00000020 PWM1CON 00000016 PortCValue 00000025 PoweringUp 0000001A PulseCheck 0000009D RAIE 00000003 RAIF 00000000 RD 00000000 RP0 00000005 RP1 00000006 ReturnedCode 00000026 SBODEN 00000004 SCS 00000000 STATUS 00000003 SWDTEN 00000000 Start 00000000 SystemState 00000027 T0CS 00000005 T0IE 00000005 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 15 SYMBOL TABLE LABEL VALUE T0IF 00000002 T0SE 00000004 T1CKPS0 00000004 T1CKPS1 00000005 T1CON 00000010 T1GINV 00000007 T1GSS 00000001 T1IE 00000000 T1IF 00000000 T1OSCEN 00000003 T2CKPS0 00000000 T2CKPS1 00000001 T2CON 00000012 T2IE 00000001 T2IF 00000001 TIME_TO_CLOSE_DOOR 30h TIME_TO_OPEN_DOOR 30h TLWODEnd 000000BC TMR0 00000001 TMR1CS 00000001 TMR1GE 00000006 TMR1H 0000000F TMR1IE 00000000 TMR1IF 00000000 TMR1L 0000000E TMR1ON 00000000 TMR2 00000011 TMR2IE 00000001 TMR2IF 00000001 TMR2ON 00000002 TOUTPS0 00000003 TOUTPS1 00000004 TOUTPS2 00000005 TOUTPS3 00000006 TRISA 00000085 TRISC 00000087 TUN0 00000000 TUN1 00000001 TUN2 00000002 TUN3 00000003 TUN4 00000004 TenthSeconds 00000029 Timer2Comp 00000028 Timer2Loop1 0000009A Timer2Loop2 000000C0 TimerLoop 00000091 ULPWUE 00000005 VCFG 00000006 VR0 00000000 VR1 00000001 VR2 00000002 VR3 00000003 VRCON 00000099 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 16 SYMBOL TABLE LABEL VALUE VREN 00000007 VRR 00000005 W 00000000 WDTCON 00000018 WDTPS0 00000001 WDTPS1 00000002 WDTPS2 00000003 WDTPS3 00000004 WPU 00000095 WPUA 00000095 WR 00000001 WREN 00000002 WRERR 00000003 WTSEnd 000000C5 WaitForOpenTheDoor 0000003F WaitHalfSecond 0000008E WaitOneSecond 0000008B WaitTenthSecond 000000BE WaitTenthWithOD 00000095 Z 00000002 _BOD_NSLEEP 00003EFF _BOD_OFF 00003CFF _BOD_ON 00003FFF _BOD_SBODEN 00003DFF _CPD_OFF 00003FFF _CPD_ON 00003F7F _CP_OFF 00003FFF _CP_ON 00003FBF _EC_OSC 00003FFB _EXTRC 00003FFF _EXTRCIO 00003FFE _EXTRC_OSC_CLKOUT 00003FFF _EXTRC_OSC_NOCLKOUT 00003FFE _FCMEN_OFF 000037FF _FCMEN_ON 00003FFF _HS_OSC 00003FFA _IESO_OFF 00003BFF _IESO_ON 00003FFF _INTOSC 00003FFD _INTOSCIO 00003FFC _INTRC_OSC_CLKOUT 00003FFD _INTRC_OSC_NOCLKOUT 00003FFC _LP_OSC 00003FF8 _MCLRE_OFF 00003FDF _MCLRE_ON 00003FFF _PWRTE_OFF 00003FFF _PWRTE_ON 00003FEF _WDT_OFF 00003FF7 _WDT_ON 00003FFF _XT_OSC 00003FF9 __16F684 00000001 __DEBUG 1 MPASM 5.20 DININGDOOR.ASM 10-19-2012 7:04:58 PAGE 17 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 00C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX ---------------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 224 Program Memory Words Free: 1824 Errors : 0 Warnings : 4 reported, 0 suppressed Messages : 8 reported, 0 suppressed